package com.rongshu.view.penpal.present;

import android.content.Context;
import android.text.TextUtils;

import com.rongshu.api.RetorfitService;
import com.rongshu.utils.Common;
import com.rongshu.utils.UserInfoUtils;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetView;
import com.rongshu.view.login.entity.PasswordLogin;
import com.rongshu.view.penpal.bean.PenpalResponse;
import com.rongshu.widget.BanyanDialog;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;
import rx.functions.Action0;

/**
 * created by zhengweis on 2018/11/22.
 * description：
 */
public class PenpalNearbyPresenter extends BasePresenter<INetView> {

    public PenpalNearbyPresenter(Context context) {
        super(context);
    }

    public String getUserCity() {
        PasswordLogin.ResponseBean userInfo = UserInfoUtils.getUserInfo();
        if (userInfo != null && !TextUtils.isEmpty(userInfo.getCity())) {
            return userInfo.getCity();
        }
        return "";
    }

    public void searchPenpalList(String content, int pageIndex, int pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", UserInfoUtils.getUserId());
        map.put("label", "");
        map.put("penclubname", "");
        map.put("district", content);
        map.put("pageIndex", pageIndex);
        map.put("pageSize", pageSize);
        RetorfitService.getPenPalListByKeyword(UserInfoUtils.getUserId(), "", "", content, pageIndex, pageSize,
                Common.encryptionSign(map)).doOnSubscribe(new Action0() {
            @Override
            public void call() {

            }
        }).subscribe(new Subscriber<PenpalResponse>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(PenpalResponse object) {
                getView().success(object, 0);
            }
        });
    }

    public void showDialog() {
        BanyanDialog.Builder builder = new BanyanDialog.Builder(mContext);
        builder.setTitle("无法获得附近笔友会");
        builder.setContent("请先在个人中心完善资料\n选择所在地区");
        builder.setLeft("取消");
        builder.setRight("完善资料");
        final BanyanDialog banyanDialog = builder.create();
        builder.setDialogOnClick(new BanyanDialog.Builder.onClickListener() {
            @Override
            public void leftClickListener() {
                banyanDialog.dismiss();
            }

            @Override
            public void rightClickListener() {
                banyanDialog.dismiss();
            }
        });
        banyanDialog.show();
    }
}
